using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using Microsoft.ApplicationBlocks.Data;
using Module.Core.EntitiesInfo;
using Module.EntitiesInfo;

namespace Module.DataAccess
{
	public class CMSZonesDB
    {
        #region ConnectionString
        private string _connectionString;
        public string ConnectionString
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }
        public CMSZonesDB()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["localsql"].ToString();
        }
        #endregion
        
		#region Methods

	
		public virtual int Insert(CMSZonesInfo cMSZonesInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ZoneIDLang", cMSZonesInfo.ZoneIDLang),
				new SqlParameter("@ParentID", cMSZonesInfo.ParentID),
				new SqlParameter("@Title", cMSZonesInfo.Title),
				new SqlParameter("@Priority", cMSZonesInfo.Priority),
				new SqlParameter("@Lang", cMSZonesInfo.Lang),
				new SqlParameter("@CreatedOn", cMSZonesInfo.CreatedOn),
				new SqlParameter("@CreatedBy", cMSZonesInfo.CreatedBy),
				new SqlParameter("@DeletedOn", cMSZonesInfo.DeletedOn),
				new SqlParameter("@DeletedBy", cMSZonesInfo.DeletedBy),
				new SqlParameter("@KeyZone", cMSZonesInfo.KeyZone),
				new SqlParameter("@ZoneUrl", cMSZonesInfo.ZoneUrl),
				new SqlParameter("@ModuleMenu", cMSZonesInfo.ModuleMenu),
				new SqlParameter("@ImagesZone", cMSZonesInfo.ImagesZone),
				new SqlParameter("@StatusClick", cMSZonesInfo.StatusClick),
				new SqlParameter("@CheckZone", cMSZonesInfo.CheckZone),
				new SqlParameter("@TrangHienThi", cMSZonesInfo.TrangHienThi)
			};

            return cMSZonesInfo.ZoneID = (int)SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "CMS_Zones_Insert", parameters);
		}

		
		public virtual void Update(CMSZonesInfo cMSZonesInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ZoneID", cMSZonesInfo.ZoneID),				
				new SqlParameter("@ParentID", cMSZonesInfo.ParentID),
				new SqlParameter("@Title", cMSZonesInfo.Title),
				new SqlParameter("@Priority", cMSZonesInfo.Priority),
				new SqlParameter("@Lang", cMSZonesInfo.Lang),
				new SqlParameter("@CreatedOn", cMSZonesInfo.CreatedOn),
				new SqlParameter("@CreatedBy", cMSZonesInfo.CreatedBy),
				new SqlParameter("@DeletedOn", cMSZonesInfo.DeletedOn),
				new SqlParameter("@DeletedBy", cMSZonesInfo.DeletedBy),
				new SqlParameter("@KeyZone", cMSZonesInfo.KeyZone),
				new SqlParameter("@ZoneUrl", cMSZonesInfo.ZoneUrl),
				new SqlParameter("@ModuleMenu", cMSZonesInfo.ModuleMenu),
				new SqlParameter("@ImagesZone", cMSZonesInfo.ImagesZone),
				new SqlParameter("@StatusClick", cMSZonesInfo.StatusClick),
				new SqlParameter("@CheckZone", cMSZonesInfo.CheckZone),
				new SqlParameter("@TrangHienThi", cMSZonesInfo.TrangHienThi)
			};

            SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "CMS_Zones_Update", parameters);
		}


        public virtual void UpdateZoneUrl(int zoneId, string zoneUrl)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@zoneId", zoneId),				
				new SqlParameter("@zoneUrl", zoneUrl)
			};

            SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "CMS_Zones_UpdateZoneUrl", parameters);
        }
		
		public virtual void Delete(int zoneID)
		{
		    try
		    {
                SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ZoneID", zoneID)
			};

                SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "CMS_Zones_Delete", parameters);
		    }
		    catch (Exception)
		    {
		        
		        throw;
		    }
		}


        public IDataReader Select(int? type, string para_1, string para_2)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "CMS_Zones_Select",type, para_1, para_2);         
            }
            catch (Exception)
            {
                
                throw;
            }            
        }

        public IDataReader SelectInfo(int? type, string para_1, string para_2)
        {
            try
            {
                return SqlHelper.ExecuteReader(ConnectionString, "CMS_Zones_Select", type, para_1, para_2);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public int GetZoneId(string zoneUrl)
        {                       
            using (DataTable dt = SqlHelper.ExecuteDataset(ConnectionString, "CMS_Zones_getZoneId", zoneUrl).Tables[0])            
            {
                if (dt.Rows.Count > 0)
                {
                    return Convert.ToInt32(dt.Rows[0]["ZoneId"]);
                }
                else
                {
                    return 0;
                }
            }
        }

        public virtual IDataReader SelectModule(int? Type, string Para_1, string Para_2)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
               new SqlParameter("@Type", Type),
                new SqlParameter("@Para_1", Para_1),
                new SqlParameter("@Para_2", Para_2)   			
			};
            return SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "CMS_Zones_SelectModuleType", parameters);
        }
       
        public DataTable GetZoneId(int? type, int para_1, int para_2)
        {
            try
            {
                return
               SqlHelper.ExecuteDataset(ConnectionString, "CMS_Zones_Select",type,  para_1, para_2).Tables[0];  
            }
            catch (Exception)
            {
                
                throw;
            }
                    
        }        
		#endregion       
	}
}
